package com.everest.tribalapp;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class Dering_Pengelola_7 extends Activity implements OnClickListener
{

	
	private Button next;
	private String[] choice;
	protected int id;
	protected String selectvalue;
	private int flag=0;
	private Button previous;
	private TextView dering_f7_qes_1;
	private TextView dering_f7_qes_2;
	private TextView dering_f7_qes_3;
	private String value;
	private EditText dering_f7_ans_1;
	private CheckBox dering_f7_ans_2a;
	private CheckBox dering_f7_ans_2b;
	private CheckBox dering_f7_ans_3a;
	private CheckBox dering_f7_ans_3b;
	private CheckBox dering_f7_ans_3c;
	private CheckBox dering_f7_ans_3d;
	private CheckBox dering_f7_ans_3e;
	private CheckBox dering_f7_ans_3f;
	private CharSequence[] MSG_VALUES_2={"Pasang stiker pada perangkat dan pintu","Tulis nomor Call Center"};
	private CharSequence[] MSG_VALUES_3={"Pengelola","Perangkat yg tersedia","Papan petunjuk","Saat mencoba telepon","Lingkungan sekitar","Sarana lainnya"};
	protected boolean[] selectVal2={false,false};
	protected boolean[] selectVal3={false,false,false,false,false,false};
	@Override
	public void onBackPressed() 
	{
		
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Dering_Pengelola_7.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.dering_pengelola7);
		
		 initialization();
		 
		
		 previous.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent in=new Intent(getApplicationContext(),Dering_Pengelola_6.class);
					startActivity(in);
					Dering_Pengelola_7.this.finish();
				}
			});
		 
		 next.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent in=new Intent(getApplicationContext(),Dering_Pengelola_8.class);
				startActivity(in);
				Dering_Pengelola_7.this.finish();
			}
		});
	}
	private void initialization() {
		
		
		next=(Button)findViewById(R.id.next);
		previous=(Button)findViewById(R.id.previous);
		dering_f7_qes_1=(TextView)findViewById(R.id.dering_f7_qes_1);
		dering_f7_ans_1=(EditText)findViewById(R.id.dering_f7_ans_1);
		dering_f7_qes_2=(TextView)findViewById(R.id.dering_f7_qes_2);
		dering_f7_qes_3=(TextView)findViewById(R.id.dering_f7_qes_3);
		dering_f7_ans_2a=(CheckBox)findViewById(R.id.checkBox_21);
		dering_f7_ans_2b=(CheckBox)findViewById(R.id.checkBox_22);
		dering_f7_ans_3a=(CheckBox)findViewById(R.id.checkBox_31);
		dering_f7_ans_3b=(CheckBox)findViewById(R.id.checkBox_32);
		dering_f7_ans_3c=(CheckBox)findViewById(R.id.checkBox_33);
		dering_f7_ans_3d=(CheckBox)findViewById(R.id.checkBox_34);
		dering_f7_ans_3e=(CheckBox)findViewById(R.id.checkBox_35);
		dering_f7_ans_3f=(CheckBox)findViewById(R.id.checkBox_36);
		dering_f7_qes_1.setOnClickListener(this);
		dering_f7_qes_2.setOnClickListener(this);
		dering_f7_qes_3.setOnClickListener(this);
		dering_f7_ans_2a.setOnClickListener(this);
		dering_f7_ans_2b.setOnClickListener(this);
		dering_f7_ans_3a.setOnClickListener(this);
		dering_f7_ans_3b.setOnClickListener(this);
		dering_f7_ans_3c.setOnClickListener(this);
		dering_f7_ans_3d.setOnClickListener(this);
		dering_f7_ans_3e.setOnClickListener(this);
		dering_f7_ans_3f.setOnClickListener(this);
	}
	@Override
	public void onClick(View v) 
	{
		if(v.getId()==dering_f7_qes_1.getId())
		{
			value=getResources().getString(R.string.dering_f7_qes_1);
			toast_msg();
		}
		else if(v.getId()==dering_f7_qes_2.getId())
		{
			value=getResources().getString(R.string.dering_f7_qes_2);
			toast_msg();
		}
		else if(v.getId()==dering_f7_qes_3.getId())
		{
			value=getResources().getString(R.string.dering_f7_qes_3);
			toast_msg();
		}
		else if(v.getId()==dering_f7_ans_2a.getId())
		{
			dering_f7_ans_2a.setChecked(false);
			msg_f7_ans_2();
		}
		else if(v.getId()==dering_f7_ans_2b.getId())
		{
			dering_f7_ans_2b.setChecked(false);
			msg_f7_ans_2();
		}
		else if(v.getId()==dering_f7_ans_3a.getId())
		{
			dering_f7_ans_3a.setChecked(false);
			msg_f7_ans_3();
		}
		else if(v.getId()==dering_f7_ans_3b.getId())
		{
			dering_f7_ans_3b.setChecked(false);
			msg_f7_ans_3();
		}
		else if(v.getId()==dering_f7_ans_3c.getId())
		{
			dering_f7_ans_3c.setChecked(false);
			msg_f7_ans_3();
		}
		else if(v.getId()==dering_f7_ans_3d.getId())
		{
			dering_f7_ans_3d.setChecked(false);
			msg_f7_ans_3();
		}
		else if(v.getId()==dering_f7_ans_3e.getId())
		{
			dering_f7_ans_3e.setChecked(false);
			msg_f7_ans_3();
		}
		else if(v.getId()==dering_f7_ans_3f.getId())
		{
			dering_f7_ans_3f.setChecked(false);
			msg_f7_ans_3();
		}
		
	}
	public void toast_msg()
	{
		LayoutInflater inflater = getLayoutInflater();

		View layout = inflater.inflate(R.layout.custom_toast,
				(ViewGroup) findViewById(R.id.custom_toast_layout_id));
		TextView text = (TextView) layout.findViewById(R.id.text);
		text.setText(value);
		Toast toast = new Toast(getApplicationContext());
		toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
		toast.setDuration(Toast.LENGTH_LONG);
		toast.setView(layout);
		toast.show();
	}
	
	
	
	 private void msg_f7_ans_2()
	   {
		     Builder builder = new AlertDialog.Builder(this);
		     builder.setTitle("Answer");
		     builder.setMultiChoiceItems(MSG_VALUES_2, selectVal2,
		         new DialogInterface.OnMultiChoiceClickListener()
		     {
		           @Override
		           public void onClick(DialogInterface dialog, int which,
		               boolean isChecked) 
		           {
		             selectVal2[which] = isChecked;
		           }
		         });
		     builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
		       @Override
		       public void onClick(DialogInterface dialog, int which) {
		         for (int i = 0; i <MSG_VALUES_2.length; i++) 
		         {
		           if (selectVal2[i]) 
		           {
		              if(i==0)
		 				{
		            	 
		 					dering_f7_ans_2a.setChecked(true);
	 					}
		 				else if(i==1)
		 				{
		 					dering_f7_ans_2b.setChecked(true);
		 				}
		 			
		           }
		           else
		           {
		        	   if(i==0)
		 				{
		            	 
		 					dering_f7_ans_2a.setChecked(false);
	 					}
		 				else if(i==1)
		 				{
		 					dering_f7_ans_2b.setChecked(false);
		 				}
		 			
		 				
		           }
		         }
		        }
		     });
		     builder.setNegativeButton("cancel",
		         new DialogInterface.OnClickListener() {
		           @Override
		           public void onClick(DialogInterface dialog, int which) {
		             dialog.dismiss();
		           }
		         });
		     AlertDialog alert = builder.create();
		     alert.show();
		   }
	 private void msg_f7_ans_3()
	   {
		     Builder builder = new AlertDialog.Builder(this);
		     builder.setTitle("Answer");
		     builder.setMultiChoiceItems(MSG_VALUES_3, selectVal3,
		         new DialogInterface.OnMultiChoiceClickListener()
		     {
		           @Override
		           public void onClick(DialogInterface dialog, int which,
		               boolean isChecked) 
		           {
		             selectVal3[which] = isChecked;
		           }
		         });
		     builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
		       @Override
		       public void onClick(DialogInterface dialog, int which) {
		         for (int i = 0; i <MSG_VALUES_3.length; i++) 
		         {
		           if (selectVal3[i]) 
		           {
		        	   if(i==0)
		 				{
		            	 
		 					dering_f7_ans_3a.setChecked(true);
	 					}
		 				else if(i==1)
		 				{
		 					dering_f7_ans_3b.setChecked(true);
		 				}else if(i==2)
		 				{
		 					dering_f7_ans_3c.setChecked(true);
		 				}else if(i==3)
		 				{
		 					dering_f7_ans_3d.setChecked(true);
		 				}else if(i==4)
		 				{
		 					dering_f7_ans_3e.setChecked(true);
		 				}else if(i==5)
		 				{
		 					dering_f7_ans_3f.setChecked(true);
		 				}
		 			
		           }
		           else
		           {
		        	   if(i==0)
		 				{
		            	 
		 					dering_f7_ans_3a.setChecked(false);
	 					}
		 				else if(i==1)
		 				{
		 					dering_f7_ans_3b.setChecked(false);
		 				}else if(i==2)
		 				{
		 					dering_f7_ans_3c.setChecked(false);
		 				}else if(i==3)
		 				{
		 					dering_f7_ans_3d.setChecked(false);
		 				}else if(i==4)
		 				{
		 					dering_f7_ans_3e.setChecked(false);
		 				}else if(i==5)
		 				{
		 					dering_f7_ans_3f.setChecked(false);
		 				}
		 			
		 				
		           }
		         }
		        }
		     });
		     builder.setNegativeButton("cancel",
		         new DialogInterface.OnClickListener() {
		           @Override
		           public void onClick(DialogInterface dialog, int which) {
		             dialog.dismiss();
		           }
		         });
		     AlertDialog alert = builder.create();
		     alert.show();
	   }
	 @Override
		protected void onPause() {
			// TODO Auto-generated method stub
			super.onPause();
			SharedPreferences preferences=getSharedPreferences("dering_f7_details", MODE_PRIVATE);
			SharedPreferences.Editor editor=preferences.edit();
			editor.putString("7_1",dering_f7_ans_1.getText().toString().trim());
			editor.putBoolean("7_2a",dering_f7_ans_2a.isChecked());
			editor.putBoolean("7_2b",dering_f7_ans_2b.isChecked());
			editor.putBoolean("7_3a",dering_f7_ans_3a.isChecked());
			editor.putBoolean("7_3b",dering_f7_ans_3b.isChecked());
			editor.putBoolean("7_3c",dering_f7_ans_3c.isChecked());
			editor.putBoolean("7_3d",dering_f7_ans_3d.isChecked());
			editor.putBoolean("7_3e",dering_f7_ans_3e.isChecked());
			editor.putBoolean("7_3f",dering_f7_ans_3f.isChecked());
			editor.commit();
		}

		@Override
		protected void onResume() {
			// TODO Auto-generated method stub
			super.onResume();
			SharedPreferences preferences=getSharedPreferences("dering_f7_details",MODE_PRIVATE);
			dering_f7_ans_1.setText(preferences.getString("7_1",""));
			dering_f7_ans_2a.setChecked(preferences.getBoolean("7_2a",false));
			dering_f7_ans_2b.setChecked(preferences.getBoolean("7_2b",false));
			dering_f7_ans_3a.setChecked(preferences.getBoolean("7_3a",false));
			dering_f7_ans_3b.setChecked(preferences.getBoolean("7_3b",false));
			dering_f7_ans_3c.setChecked(preferences.getBoolean("7_3c",false));
			dering_f7_ans_3d.setChecked(preferences.getBoolean("7_3d",false));
			dering_f7_ans_3e.setChecked(preferences.getBoolean("7_3e",false));
			dering_f7_ans_3f.setChecked(preferences.getBoolean("7_3f",false));
		}
}
